home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / us20src.zip / CHECK.C < prev    next >
C/C++ Source or Header  |  1992-06-26  |  3KB  |  126 lines

  1. /*    CHECK:    Dictionary scan module for MicroSPELL 2.0
  2.         Spell Checker and Corrector
  3.  
  4.         (C)opyright May 1987,1992 by Daniel Lawrence
  5.         All Rights Reserved
  6.  
  7. */
  8.  
  9. #include    <stdio.h>
  10. #include    "dopt.h"
  11. #include    "dstruct.h"
  12. #include    "ddef.h"
  13.  
  14. check()
  15.  
  16. {
  17.     int i;        /* index into the word list */
  18.  
  19.     /* sort the source words */
  20.     if (swdebug)
  21.         printf("[%u words being checked...\n", numwords);
  22.     wordsort();
  23.     if (swdebug)
  24.         printf("  sorted...");
  25.  
  26.     /* merge them against the dictionary */
  27.     merge();
  28.     if (swdebug)
  29.         printf("checked\n");
  30.  
  31.     /* sort them back into position order */
  32.     possort();
  33.     if (swdebug) {
  34.         printf("  sorted in position order...");
  35.         printf("%u mismatched words]\n", badwords);
  36.     }
  37.  
  38.     /* dump the list to disk */
  39.     dumplist();
  40.  
  41.     /* lastly, de-allocate the word list */
  42.     while (numwords > 0)
  43.         free(sword[--numwords]);
  44. }
  45.  
  46. int merge()        /* do a merge run against the main dictionary    */
  47.  
  48. {
  49.     register int cindex;    /* current word index */
  50.     register char *cword;    /* ptr to current word */
  51.     register int cmp;    /* result of current comparision */
  52.     register int mismatch;    /* number of mismatched words */
  53.     char mword[NSTRING];    /* current dictionary word */
  54.  
  55.     /* open the main dictionary */
  56.     if (mopen() == FALSE)
  57.         exit(EXMDICT);
  58.  
  59.     /* start with a LOW VALUES dictionary word */
  60.     mword[0] = 0;
  61.     mismatch = 0;
  62.  
  63.     strcpy(mword, nxtmword());
  64.  
  65.     for (cindex = 0; cindex < numwords; cindex++) {
  66.  
  67.         /* get the current word */
  68.         cword = sword[cindex]->w_text;
  69.  
  70.         /* scan the dictionary for a match */
  71.         cmp = lowcmp(cword, mword);
  72.         while (cmp > 0) {
  73.             strcpy(mword, nxtmword());
  74.             cmp = lowcmp(cword, mword);
  75.         }
  76.  
  77.         /* if this word is not matched..... */
  78.         if (cmp != 0) {
  79.             if (mismatch == cindex)
  80.                 ++mismatch;
  81.             else {
  82.                 sword[mismatch++] = sword[cindex];
  83.                 sword[cindex] = NULL;
  84.             }
  85.         } else {
  86.             free(sword[cindex]);
  87.             sword[cindex] = NULL;
  88.         }
  89.     }
  90.     numwords = mismatch;
  91.     badwords += mismatch;
  92.     mclose();
  93. }
  94.  
  95. dumplist()
  96.  
  97. {
  98.     int i;
  99.  
  100.     /* if there is a user dictionary, dump its name out */
  101.     if (*userlist)
  102.         if (swwords)
  103.             fprintf(outfile, "USER LIST: %s\n", userlist);
  104.         else
  105.             fprintf(outfile, "-3\n%s\n", userlist);
  106.  
  107.     for (i = 0; i < numwords; i++) {
  108.  
  109.         /* if we are in a new file... write a file header */
  110.         if (outnum != sword[i]->w_file) {
  111.             outnum = sword[i]->w_file;
  112.             if (swwords)
  113.                 fprintf(outfile, "FILE: %s\n", splname[outnum]);
  114.             else
  115.                 fprintf(outfile, "-1\n%s\n", splname[outnum]);
  116.         }
  117.  
  118.         /* write the row and column number of the current word */
  119.         if (swwords)
  120.             fprintf(outfile, "%s\n", sword[i]->w_text);
  121.         else
  122.             fprintf(outfile, "%u\n%u\n",
  123.                 sword[i]->w_line, sword[i]->w_col);
  124.     }
  125. }
  126.